﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloneClass
{
    public class CloneT<T >
    {
        private T value = default(T);
        public CloneT(T a)
        {
            value = a;
        }
        public void ChangeSource(T b)
        {
            value=b;
        }
        public T Clone()
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter Formatter =
    new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(null, new System.Runtime.Serialization.StreamingContext(System.Runtime.Serialization.StreamingContextStates.Clone));
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            Formatter.Serialize(stream, value);
            stream.Position = 0;
            object clonedObj = Formatter.Deserialize(stream);
            stream.Close();
            stream.Dispose();
            return (T)clonedObj;
        }
        
    }
}
